function Class() {
	var me = this;
	var data;

	me.data = {
		buffs : []
	};
	
	me.Events = {
		'selfbuffchanged' : []
	};
}

Class.prototype = new Event();

Class.prototype.addBuff = function(buff) {
	var me = this;

	me.Buffs.push(buff);
};

Class.prototype.getBuff = function(buffId) {
	var me = this;
	var buffs = [];
	
	for (var i = 0; i < me.Buffs.length; i++) {
		if (me.Buffs[i].Id == buffId)
			buffs.push(me.Buffs[i]);
	}
	if (buffs.length == 0)
		return null; // Pour l'instant, TODO renvoyer une collection vide
	if (buffs.length == 1)
		return buffs[0];
	return new BuffCollection(buffs);
};

Class.prototype.getMultModifier = function(name) {
	var me = this;
	var modifier = 1.00;
	
	var maxMultPriority = 1;
	
	for (var i = 0; i < me.Buffs.length; i++) {
		if (maxMultPriority < me.Buffs[i].data.multPriority) {
			maxMultPriority = me.Buffs[i].data.multPriority;
		}
	}

	var currentPriority = 1;
	
	while (currentPriority <= maxMultPriority) {
		var tempModifier = 1.00;
		for (var i = 0; i < me.Buffs.length; i++) {
			var buff = me.Buffs[i];
			if (buff.Mod == name && buff.Method == 'mult' && buff.data.multPriority == currentPriority) {
				tempModifier += buff.Amount;
			}
		}
		modifier *= tempModifier;
		currentPriority++;
	}
	return modifier;
};

Class.prototype.getAddModifier = function(name) {	
	var me = this;
	var modifier = 0.00;
	
	for (var i = 0; i < me.Buffs.length; i++) {
		var buff = me.Buffs[i];
		
		if (buff.Mod == name && buff.Method == 'add') {
			modifier += buff.Amount;
		}
	}
	return modifier;
};

Class.prototype.getModifier = function(name, method) { // TODO check la bonne valeur des arguments
	var me = this;
	var modifier = ((method == 'mult') ? (me.getMultModifier(name)) : (me.getAddModifier(name)));
	
	console.log("Modifier for " + name + " " + method + " : " + modifier);

	return modifier;
	
	var modifier = ((method == 'mult') ? (1.00) : (0.00));
	
	for (var i = 0; i < me.Buffs.length; i++) {
		var buff = me.Buffs[i];
		
		if (buff.Mod == name && buff.Method == method) {
			modifier += buff.Amount;
		}
	}
	
	console.log("Modifier for " + name + " " + method + " : " + modifier);
	
	return modifier;
};

/* Class.prototype.getModifier = function(name, method) { // TODO check la bonne valeur des arguments
	var me = this;
	var modifier;
	
	switch (name) {
		case 'defenseRate' :
			switch (method) {
				case 'add' :
					modifier = me.getDefenseRateAdditiveModifier();
					break;
				case 'mult' :
					modifier = me.getDefenseRateMultiplicativeModifier();
					break;
			}
			break;
	}
	return modifier;
}; */

Class.prototype.getDefenseRateMultiplicativeModifier = function() {
	var me = this;
	var modifier = 1.0;
	
	for (var i = 0; i < me.Buffs.length; i++) {
		var buff = me.Buffs[i];
		
		if (buff.Mod == 'defenseRate' && buff.Method == 'mult') {
			modifier += buff.Amount;
		}
	}
	return modifier;
};

Class.prototype.getDefenseRateAdditiveModifier = function() {
	var me = this;
	var modifier = 0.0;
	
	for (var i = 0; i < me.Buffs.length; i++) {
		var buff = me.Buffs[i];
		
		if (buff.Mod == 'defenseRate' && buff.Method == 'add') {
			modifier += buff.Amount;
		}
	}
	return modifier;
};

Object.defineProperty(Class.prototype, "Buffs", {
	get : function() {
		return this.data.buffs;
	}
});
